﻿using System;
using System.IO;

namespace MyFileView.Shard
{
    public class UploadFileModel
    {
        public string Id { get; set; } = Guid.NewGuid().ToString("N");
        public string FileName { get; set; }

        public string ContentType { get; set; }

        public string FilePath { get; set; } = string.Empty;

        // public string FileType { get; set; } = string.Empty;

        public string FileSize { get { return ComputeFileSize(); } }

        public long FileSizeByte { get; set; }
  
        public string FileSuffix { get; set; } = string.Empty;

        /// <summary>
        /// 计算文件大小添加后缀
        /// </summary>
        /// <returns></returns>
        private string ComputeFileSize()
        {
            string[] sizes = { "B", "KB", "MB", "GB", "TB" };
            double len = FileSizeByte;
            int order = 0;
            while (len >= 1024 && order < sizes.Length - 1)
            {
                order++;
                len = len / 1024;
            }
            //var res= String.Format("{0:0.##} {1}", len, sizes[order]);
            //var val = sizes[order];

            return  String.Format("{0:0.##} {1}", len, sizes[order]);
        }

    }
}